package services

import (
	"ContentSystem/internal/api/operate"
	"fmt"
	"github.com/gin-gonic/gin"
	"net/http"
)

type ContentDeleteReq struct {
	Id int `json:"id" binding:"required" `
}

type ContentDeleteResp struct {
	Message string `json:"message" binding:"required"`
}

func (c *CmsApp) ContentDelete(ctx *gin.Context) {

	var req ContentDeleteReq
	if err := ctx.ShouldBindJSON(&req); err != nil {
		ctx.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
		return
	}

	fmt.Println("ID", req.Id)

	resp, err := c.operateAppClient.DeleteContent(ctx, &operate.DeleteContentReq{
		Id: int64(req.Id),
	})

	//contentDao := dao.NewContentDao(c.db)
	//ok, err := contentDao.IsExist(req.Id)
	if err != nil {
		ctx.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
		return
	}
	//
	//if !ok {
	//	ctx.JSON(http.StatusInternalServerError, gin.H{"error": "内容不存在"})
	//	return
	//}
	//err = contentDao.Delete(req.Id)
	//
	//if err != nil {
	//	ctx.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
	//	return
	//}

	// 响应
	ctx.JSON(http.StatusOK, gin.H{
		"code":    0,
		"message": "ok",
		"data":    resp,
	})
}
